package com.lsa.letcode.the48.rotateImg;

import static org.junit.Assert.assertArrayEquals;

import org.junit.Test;

import com.lsa.letcode.common.LetCodeTestBase;

public class RotateImgTest extends LetCodeTestBase{
	@Test
	public void test() {
		Solution s = new Solution();
		
		int[][] matrix = new int[][]{{0,1,2,3,4,5},{6,7,8,9,10,11},{12,13,14,15,16,17},{18,19,20,21,22,23},{24,25,26,27,28,29},{30,31,32,33,34,35}};
		s.rotate(matrix);
		print(matrix);
		
		test(s, new int[][] {}, new int[][] {});
		
		test(s, new int[][] { { 0, 1, 2, 3, 4, 5 }, { 6, 7, 8, 9, 10, 11 },
				{ 12, 13, 14, 15, 16, 17 }, { 18, 19, 20, 21, 22, 23 },
				{ 24, 25, 26, 27, 28, 29 }, { 30, 31, 32, 33, 34, 35 } },
				new int[][] { { 30, 24, 18, 12, 6, 0 },
						{ 31, 25, 19, 13, 7, 1 }, { 32, 26, 20, 14, 8, 2 },
						{ 33, 27, 21, 15, 9, 3 }, { 34, 28, 22, 16, 10, 4 },
						{ 35, 29, 23, 17, 11, 5 } });
		test(s, new int[][] { { 0, 1, 2, 3, 4 }, { 5, 6, 7, 8, 9 },
				{ 10, 11, 12, 13, 14 }, { 15, 16, 17, 18, 19 },
				{ 20, 21, 22, 23, 24 } }, new int[][] { { 20, 15, 10, 5, 0 },
				{ 21, 16, 11, 6, 1 }, { 22, 17, 12, 7, 2 },
				{ 23, 18, 13, 8, 3 }, { 24, 19, 14, 9, 4 } });

		// int[][] matrix = new
		// int[][]{{0,1,2,3},{4,5,6,7},{8,9,10,11},{12,13,14,15}};
		// s.rotate(matrix);
		// print(matrix);

		test(s, new int[][] { { 0, 1, 2, 3 }, { 4, 5, 6, 7 }, { 8, 9, 10, 11 },
				{ 12, 13, 14, 15 } }, new int[][] { { 12, 8, 4, 0 },
				{ 13, 9, 5, 1 }, { 14, 10, 6, 2 }, { 15, 11, 7, 3 } });

		test(s, new int[][] { { 113 } }, new int[][] { { 113 } });
		test(s, new int[][] { { 0, 1 }, { 2, 3 } }, new int[][] { { 2, 0 },
				{ 3, 1 } });
		test(s, new int[][] { { 0, 1, 2 }, { 2, 3, 4 }, { 5, 6, 7 } },
				new int[][] { { 5, 2, 0 }, { 6, 3, 1 }, { 7, 4, 2 } });
	}

	private void test(Solution s, int[][] input, int[][] expected) {
		s.rotate(input);
		assertArrayEquals(expected, input);
	}
	
	int[] coords(int x, int y) {
		return new int[]{x, y};
	}
}